package com.orangelife.mobile.surrounding.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.curry.android.adapter.FatherAdapter;
import com.curry.android.net.NetworkUtil;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.surrounding.activity.SearchConditionActivity;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Created by YangWei
 * on 2015/10/10.
 */
public class SearchConditionListViewAdapter<T> extends FatherAdapter<T> {

    private Context context;
    private List<T> list;
    @Override
    public BaseAdapter setList(List<T> list) {
        this.list = list;
        return SearchConditionListViewAdapter.this;
    }

    public SearchConditionListViewAdapter(Context context,List<T> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_lv_circumtesco_searchcondition, null);
            holder.tvGoodsName = (TextView) convertView.findViewById(R.id.tvGoodsName);
            holder.llClick = (LinearLayout) convertView.findViewById(R.id.llClick);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
		/*listview填数据*/
        Map<String,Object> map= (Map<String, Object>) list.get(position);
        holder.tvGoodsName.setText(map.get("keyword").toString());
//        holder.llClick.setOnClickListener(new listener(map));
        return convertView;
    }

    class listener implements View.OnClickListener{

        private  Map<String,Object> map=null;
        public listener(Map<String, Object> map){
            this.map = map;
        }
        @Override
        public void onClick(View view) {
            if (!NetworkUtil.isConnectedNet(context)) {
                Toast.makeText(context,
                        context.getResources().getString(R.string.net_disconnected),
                        Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putSerializable("detail", (Serializable) map);
            intent.setClass(context, SearchConditionActivity.class);
            intent.putExtras(bundle);
            context.startActivity(intent);
        }
    }

    class ViewHolder{
        /**商品名称*/
        private TextView tvGoodsName;
        /**点击事件*/
        private LinearLayout llClick;
    }
}
